package com.zsh.rabbitmq.two;

import com.rabbitmq.client.Channel;
import com.zsh.rabbitmq.utils.RabbitMQUtils;

import java.util.Scanner;

/**
 * @author zsh
 * @Description 生产者 发送消息
 * @create 2022-04-26 14:27
 */
public class Task01 {
    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();

        //声明队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        //发送消息
        //从控制台接收消息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
           String msg = scanner.next();
           channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
            System.out.println("发送消息完成：" + msg);
        }

    }
}
